<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">

<head>
<title><spring:message code="title.create.user" /></title>
<script type='text/javascript' src='/BriefcaseWeb/dwr/engine.js'></script>
<script type='text/javascript'
	src='/BriefcaseWeb/dwr/interface/UserRepo.js'></script>
<script type='text/javascript' src='/BriefcaseWeb/dwr/util.js'></script>
<script language=JavaScript type=text/javascript>

	//test the username element of a form
	function isValidUsername(form){
	if (form.userName.value == "") {
        alert('Please enter a Username.');
        form.userName.focus();
        return false;
	}
	return true;
	}
	
	//Check whether Username already Exist in DB
	function isUserAlreadyExist(form) {
    //test username
    if (!isValidUsername(form)) {
        return;
    }
    
    var username = dwr.util.getValue(form.userName.id);
    UserRepo.retreiveUserByUserName(username, function(str)
    								{
    								if(str != null){
    								if(str.userName != null && str.userName!=''){
    								alert(username+' Already Exist. Please use another Username');
    								return false;
    								}
    								}else{
    								alert('Username is valid and not in use.'); 
    								return true;
    								}
    								});
    }
	</script>
</head>

<body>
<div><jsp:include flush="true" page="header_without_username.jsp"></jsp:include></div>

<div align="left"><spring:message code="${message}" text="" /></div>
<!-- Folder Creation Form -->
<form:form name="NewUserForm" method="post">
	<div align="left" class="body1">
	<link rel="stylesheet" type="text/css"
		href="<spring:theme code="site.css"/>" />
	<link rel="stylesheet" type="text/css"
		href="<spring:theme code="form.css"/>" />
	<table id="createUser">
		<tr>
			<td class="newusrtitle">New User Registration</td>
		</tr>
		<tr>
			<td class="note">*Indicates required field</td>
		</tr>
		<tr>
			<td class="txtnormal"><font color="#0C8A29">Create Your
			Account</font></td>
		</tr>
		<tr>
			<td align="right" class="txtnormal">User Name*</td>
			<td class="login_txtbox"><form:input path="userName"
				onchange="javascript:isUserAlreadyExist(document.NewUserForm);" /></td>
			<td class="error"><form:errors path="userName" /></td>
			<td><a
				href="javascript:isUserAlreadyExist(document.NewUserForm);"
				onmouseover="self.status='Click here to see if Username already Exist'; return true">
			<img src='<spring:theme code="qm.logo"/>' alt="Find" align="left"
				width="20" height="20" /></a></td>
		</tr>
		<tr>
			<td align="right" class="txtnormal">First Name*</td>
			<td class="login_txtbox"><form:input path="firstName" /></td>
			<td class="error"><form:errors path="firstName" /></td>
		</tr>
		<tr>
			<td align="right" class="txtnormal">Last Name*</td>
			<td class="login_txtbox"><form:input path="lastName" /></td>
			<td class="error"><form:errors path="lastName" /></td>
		</tr>
		<tr>
			<td align="right" class="txtnormal">Email Id*</td>
			<td class="login_txtbox"><form:input path="email" /></td>
			<td class="error"><form:errors path="email" /></td>
		</tr>
		<tr>
			<td align="right" class="txtnormal">Password*</td>
			<td class="login_txtbox"><form:password path="password" /></td>
			<td class="error"><form:errors path="password" /></td>
		</tr>
		<tr>
			<td align="right" class="txtnormal">Confirm Password*</td>
			<td class="login_txtbox"><form:password path="confirmPassword" /></td>
			<td class="error"><form:errors path="confirmPassword" /></td>
		</tr>
	</table>
	<input type="submit" value="Submit" class="button" align="middle"/>
	<input type="reset" value="Reset!" class="button" align="middle"/></div>
</form:form>

</body>
</html>
